
    /*头部*/
    var params=Params();
    var search=$('#clickSearch');
    var productA=$('#product a');
    clickQuery(search,'#content');
    clickTiggle();
    example();
    customerService();




    /*客户服务*/
    function customerService(){
        $('#service img,#service div span').mouseenter(function(){
            $('#service div a').css("visibility","visible");
        });
        $('#service').mouseleave(function(){
            $('#service div a').css("visibility","hidden");
        })
    }
    /*点击显示隐藏*/
    function clickTiggle(){
        var navSpan=$('#sub_nav>span');
        var subNav=$('#subNav');
        var sub_nav=$('#sub_nav');
        navSpan.mouseenter(function(){
            subNav.stop().slideDown();
        });
        sub_nav.mouseleave(function(){
            subNav.stop().slideUp();
        });
    }
    /*登录验证*/
    function loginTest(){
        var userName=LsyCookie.getItem('loginUser');
        if(userName){
            var login=$('#login');
            var register=$('#register');
            var me=$('#me');
            me.attr("href","user.html");
            login.text(userName).attr("href","user.html");
            register.text('退出登录').attr("href","javascript:;");
            register.click(function(){
                var bool=confirm("您确定要退出登录？");
                if(bool){
                    LsyCookie.clearAll();
                    window.location.href='index.html';
                }
            })
        }
    }
    /*选择页面ID*/
    function Params() {
        var result = {};
        var arr = location.search.replace(/^\?/, '').split(/\&/g);
        result.docName = location.pathname.match(/\/([a-zA-Z_]+)\.html$/)[1];
        result.hash = location.hash.replace(/^\#/, '');
        for (var i = 0, n = arr.length; i < n; i++) {
            var key = arr[i].split(/\=/)[0];
            result[key] = arr[i].split(/\=/)[1];
        }
        return result;
    }
    /*点击搜索*/
    function clickQuery(search,event){
        var huntText=$('#huntText').val();
        var searchDatas=LsySession.getItem('search');
        searchDatas=searchDatas?searchDatas :['无线音响','汽车扬声器','蓝牙音箱'];
        LsySession.setItem("search",searchDatas);
        for(var i=0;i<searchDatas.length;i++){
            productA.eq(i).text(searchDatas[i]);
        }
        search.click(function(e){
            var content=$(event).val();
            console.log(content);
            e.preventDefault();
            searchGoods(content);
        })
    }
    /*点击例子搜索*/
    function example(){
        productA.click(function(){
            var contents=$('#content');
            contents.val($(this).text());
            searchGoods($(this).text());
        })
    }
    /*查询*/
    function searchGoods(content){
        var page=params.docName;
        var searchText=LsySession.getItem('search');
        if(page!='shop_list'){
            window.location.href='shop_list.html?search='+content;
        }else{
            clickSearch(content);
        }
        if(content && content!=searchText[0]){
            searchText.unshift(content);
            if(searchText.length>3){
                searchText.pop();
            }
            LsySession.setItem("search",searchText);
            for(var i=0;i<searchText.length;i++){
                productA.eq(i).text(searchText[i]);
            }
        }
    }
    /*搜索*/
    function clickSearch(contentVal){
        var reg=new RegExp(contentVal,'i');
        var shopListDatas=LsyStorage.getArr('shopList');
        var shopDatas=[];
        shopListDatas.forEach(function(item){
            var title=item.title;
            if(reg.test(title)){
                shopDatas.push(item);
            }
        });
        createHtmlShop(shopDatas);
    }
    /*写入HTML*/
    function createHtmlShop(shopLists) {
        var goods=$('#goods');
        var str = '';
        for (var i = 0; i < shopLists.length; i++) {
            str += '<li>'
                + '<a href="pro_details.html?id=' + shopLists[i].id + '">'
                + '<img src="' + shopLists[i].imgSrc + '" alt="shop_list_7.png">'
                + '<p class="title">' + shopLists[i].title + '</p>'
                + '</a>'
                + '<span>¥<i>' + shopLists[i].price + '</i></span>'
                + '<div>'
                + '<b><i>' + shopLists[i].comment + '</i>评价</b>'
                + '<div>'
                + '<img class="shop-house" src="img/shop_list_14.png" alt="shop_list_14.png">'
                + '<img class="shop-car" data-id=' + shopLists[i].id + ' src="img/shop_list_15.png" alt="shop_list_15.png">'
                + '</div>'
                + '</div>'
                + '</li>';
        }
        goods.html(str);
    }
    /*验证输入的数必须是整数*/
    function integer(text){
        return text.replace(/([^\d]+|^0+)/,'');
    }
    /*输入框值数值限制*/
    function inputNum(event){
        $(event).keyup(function(){
            var text=$(this).val();
            text=integer(text);
            $(this).val(text);
        });
    }
